﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KLADR
{
    public partial class FormSelectStreet : Form
    {
        private string streetCode;
        private string streetName;
        private string stringSocr;
        private bool isChanged;

        public bool IsChanged { get { return isChanged; } }
        public string StreetCode { get { return streetCode; } }
        public string StreetName { get { return streetName; } }
        public string StreetSocr { get { return stringSocr; } }
        public string SetText { set { this.Text = value; } }

        public object DataSource { get { return streetBindingSource.DataSource; } set { streetBindingSource.DataSource = value; } }
        public FormSelectStreet()
        {
            InitializeComponent();
            streetCode = "";
            streetName = "";
            stringSocr = "";
            isChanged = false;
        }

        private void AcceptSelection()
        {
            streetName = toolStripTextBoxRegion.Text;
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }

        private void buttonAccept_Click(object sender, EventArgs e)
        {
            AcceptSelection();
        }

        private void UpdateText()
        {
            kladrDataSet.streetRow currow = (streetBindingSource.Current as DataRowView).Row as kladrDataSet.streetRow;
            try
            {
                streetName = currow.name.Trim().ToUpper();
                stringSocr = currow.socr.Trim().ToUpper();
                streetCode = currow.code;
                toolStripTextBoxRegion.Text = streetName;
                toolStripTextBoxRegionSocr.Text = stringSocr;
                isChanged = false;
            }
            catch (Exception)
            {
            }
        }

        private void regionBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            UpdateText();
        }

        private void FormSelectRegion_Load(object sender, EventArgs e)
        {
            // TODO: данная строка кода позволяет загрузить данные в таблицу "kladrDataSet1.street". При необходимости она может быть перемещена или удалена.
            //this.streetTableAdapter.Fill(this.kladrDataSet1.street);
           // UpdateText();
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            AcceptSelection();
        }

        private void toolStripTextBoxRegion_TextChanged(object sender, EventArgs e)
        {
            isChanged = true;
        }
    }
}
